package bishihuizong;

import java.util.Scanner;

/**
 * Created by JiaJia on 2019/9/16 0016.
 */
public class Kuaishou03 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNext()){
            int n=scanner.nextInt();
            int[] input=new int[n];
            for (int i = 0; i <n ; i++) {
                input[i]=scanner.nextInt();
            }
            System.out.println(solution(input));
        }scanner.close();
    }
    private static int solution(int[] input){
        int len=input.length;
        int sum=0;
        for (int i = 0; i <len ; i++) {
            sum+=input[i];
        }
        int[][] dp=new int[len+1][sum/2+1];
        for (int i = 1; i <=len ; i++) {
            for (int j = i; j <=sum/2 ; j++) {
                if (j>=input[i-1]){
                    dp[i][j]=Math.max(dp[i-1][j],dp[i-1][j-input[i-1]]+input[i-1]);
                }else {
                    dp[i][j]=dp[i-1][j];
                }
            }
        }
        return sum-2*dp[len][sum/2];
    }
}